﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace LCWMS
{
    public partial class w_so017_ld : DockContent
    {
        private DataSet dscustomer;
        private DataSet ds_department;
        public w_so017_ld()
        {
            InitializeComponent();
            dg_ship_header.AutoGenerateColumns = false;
            dg_ship_detail.AutoGenerateColumns = false;
          
        }

        #region 自定义函数
        private void f_disply_detail(string str_consi, string str_so)
        {
            string str_common;
            DataSet ds_ship_detail;
            str_common = "select b.consignor,b.so_no,b.so_line_no,b.sku,b.pack_code,b.plan_so_qty_m,b.plan_so_qty_s,allocate_qty_m,";
            str_common = str_common + "b.allocate_qty_s,b.pick_qty_m,b.pick_qty_s,b.ship_qty_m,b.ship_qty_s,";
            str_common = str_common + "b.order_price,b.order_unit,b.plan_cubage,b.plan_gross_weight,b.plan_net_weight,";
            str_common = str_common + "b.allocate_cubage,b.allocate_gross_weight,b.allocate_net_weight,b.pick_cubage,";
            str_common = str_common + "b.pick_gross_weight,b.pick_net_weight,b.ship_cubage,";
            str_common = str_common + "b.ship_gross_weight,b.ship_net_weight,b.convert_modulus,";
            str_common = str_common + " case b.main_sub_flag  when '0' then '" + main.g_class.comm_getchangestring("main", main.g_info_dataset).ToString() + "' ";
            str_common = str_common + " when '1' then '" + main.g_class.comm_getchangestring("sub", main.g_info_dataset).ToString() + "' ";
            str_common = str_common + " end main_sub_flag, ";
            str_common = str_common + " case so_status  when '0' then '" + main.g_class.comm_getchangestring("Make", main.g_info_dataset).ToString() + "' ";
            str_common = str_common + " when '1' then '" + main.g_class.comm_getchangestring("allocation", main.g_info_dataset).ToString() + "' ";
            str_common = str_common + " when '3' then '" + main.g_class.comm_getchangestring("Part Pick", main.g_info_dataset).ToString() + "' ";
            str_common = str_common + " when '4' then '" + main.g_class.comm_getchangestring("all pick", main.g_info_dataset).ToString() + "' ";
            str_common = str_common + " when '5' then '" + main.g_class.comm_getchangestring("Shipped", main.g_info_dataset).ToString() + "' ";
            if (main.dbtype == "SQL") //sql数据库
            {
                str_common = str_common + " end so_status,isnull((select case e.spare_flag when '1' then round(b.ship_qty_m/e.qty05,0) else round(b.ship_qty_m/(e.qty03 * e.qty02),0) end  from " + main.g_space + ".mst_pack e where b.inv_org = e.inv_org and b.consignor =e.consignor and b.sku = e.sku and b.pack_code = e.pack_code),0)  as box  ";
                str_common = str_common + ",b.made_time temp_date";
            }
            else
            {
                str_common = str_common + " end so_status,nvl((select case e.spare_flag when '1' then round(b.ship_qty_m/e.qty05,0) else round(b.ship_qty_m/(e.qty03 * e.qty02),0) end  from " + main.g_space + ".mst_pack e where b.inv_org = e.inv_org and b.consignor =e.consignor and b.sku = e.sku and b.pack_code = e.pack_code),0)  as box  ";
                str_common = str_common + ",b.made_time temp_date";
            }

            str_common = str_common + ",c.standby_8,b.standby_3 from " + main.g_space + ".so_ship_detail b," + main.g_space + ".mst_sku c where b.inv_org=c.inv_org and b.consignor=c.consignor and b.sku=c.sku and b.inv_org = '" + main.g_org + "' and b.consignor='" + str_consi + "' and b.so_no='" + str_so + "'";
            try
            {
                if (main.dbtype == "SQL") //sql数据库
                    ds_ship_detail = main.dbservice.Sql_exec_selectsql(str_common);
                else //默认oracle数据库
                    ds_ship_detail = main.dbservice.oracle_exec_selectsql(str_common);
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Failed! ", main.g_info_dataset) + ee.ToString());
                return;
            }
            this.dg_ship_detail.DataSource = ds_ship_detail.Tables[0];

            if (ds_ship_detail.Tables[0].Rows.Count > 0)//说明有数据,增加合计
            {
                f_add_ship();
            }
        }

        //添加出货明细的合计行
        private void f_add_ship()
        {
            decimal d_1, d_2, d_3, d_4, d_5, d_6;
            DataTable dt_put;
            if (dg_ship_detail.DataSource != null)
            {
                //增加一个合计行 
                dt_put = (DataTable)dg_ship_detail.DataSource;
                d_1 = (decimal)dt_put.Compute("Sum(" + dt_put.Columns["ship_qty_m"].ColumnName + ")", "true");
                d_2 = (decimal)dt_put.Compute("Sum(" + dt_put.Columns["ship_qty_s"].ColumnName + ")", "true");
                d_3 = (decimal)dt_put.Compute("Sum(" + dt_put.Columns["ship_cubage"].ColumnName + ")", "true");
                d_4 = (decimal)dt_put.Compute("Sum(" + dt_put.Columns["ship_gross_weight"].ColumnName + ")", "true");
                d_5 = (decimal)dt_put.Compute("Sum(" + dt_put.Columns["ship_net_weight"].ColumnName + ")", "true");
                d_6 = (decimal)dt_put.Compute("Sum(" + dt_put.Columns["box"].ColumnName + ")", "true");
                DataRow dr = dt_put.NewRow();
                dr["pack_code"] = "合计";
                dr["ship_qty_m"] = d_1;
                dr["ship_qty_s"] = d_2;
                dr["ship_cubage"] = d_3;
                dr["ship_gross_weight"] = d_4;
                dr["ship_net_weight"] = d_5;
                dr["box"] = d_6;
                ((DataTable)dg_ship_detail.DataSource).Rows.InsertAt(dr, ((DataTable)dg_ship_detail.DataSource).Rows.Count);
            }
        }

        private void f_disply(string str_customer, string str_sono)
        {
            string str_sql = "select * from " + main.g_space + ".so_ship_header a where a.inv_org='" + main.g_org + "' and consignor='" + str_customer + "' and so_no='" + str_sono + "'";
            DataSet ds_query;
            //提取数据
            try
            {

                if (main.dbtype == "SQL")
                    ds_query = main.dbservice.Sql_exec_selectsql(str_sql);
                else
                    ds_query = main.dbservice.oracle_exec_selectsql(str_sql);
                if (ds_query.Tables[0].Rows.Count > 0)
                {
                    cbx_newstandby_8.Text = ds_query.Tables[0].Rows[0]["standby_8"].ToString().Trim();
                    //初始化领料原因

                    cbx_newcustomer.Text = ds_query.Tables[0].Rows[0]["consignor"].ToString().Trim();
                    cbx_newstandby_2.Text = ds_query.Tables[0].Rows[0]["standby_2"].ToString().Trim();
                    cbx_newstandby_7.Text = ds_query.Tables[0].Rows[0]["standby_7"].ToString().Trim();
                    tb_newmaker.Text = ds_query.Tables[0].Rows[0]["applier"].ToString().Trim();
                    tb_newso.Text = ds_query.Tables[0].Rows[0]["so_no"].ToString().Trim();
                    tb_MO.Text = ds_query.Tables[0].Rows[0]["customer_sale_no"].ToString().Trim();
                    tb_newmemo.Text = ds_query.Tables[0].Rows[0]["memo"].ToString().Trim();
                    tb_memo2.Text = ds_query.Tables[0].Rows[0]["memo2"].ToString().Trim();
                    if (ds_department.Tables[0].Rows.Count > 0)
                    {
                        DataRow[] dr_de = ds_department.Tables[0].Select("dept_code = '" + cbx_newstandby_2.Text.Trim() + "'");
                        if (dr_de.Length > 0)
                        {
                            tb_newstandby_2_name.Text = dr_de[0]["dept_name"].ToString().Trim();

                        }
                        else
                        {
                            tb_newstandby_2_name.Text = "";
                        }
                    }
                }
                else
                {
                    f_Clear();
                }
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get bill's Information", main.g_info_dataset) + "!" + ee.ToString());

            }
        }

        private void f_Clear()
        {
            cbx_newstandby_8.Text = "";
            cbx_newcustomer.Text = "";
            tb_newcusname.Text = "";
            cbx_newstandby_2.Text = "";
            tb_newstandby_2_name.Text = "";
            cbx_newstandby_7.Text = "";
            tb_newmaker_id.Text = "";
            tb_newmaker.Text = "";
            tb_newso.Text = "";
            tb_MO.Text = "";
            tb_newmemo.Text = "";
            tb_memo2.Text = "";
        }
        #endregion

        private void w_so017_ld_Load(object sender, EventArgs e)
        {
            //初始化货主编码 
            try
            {
                dscustomer = main.g_class.comm_get_consignor();

                cbx_customer.ValueMember = "consignor";
                cbx_customer.DisplayMember = "consignor";
                DataRow drnew;
                drnew = dscustomer.Tables[0].NewRow();
                drnew["consignor"] = "";
                drnew["consignor_name"] = "";
                dscustomer.Tables[0].Rows.Add(drnew);
                cbx_customer.DataSource = dscustomer.Tables[0];

                 cbx_newcustomer.ValueMember = "consignor";
                cbx_newcustomer.DisplayMember = "consignor";
                cbx_newcustomer.DataSource = dscustomer.Tables[0];

            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Fail to get Consignor's Information", main.g_info_dataset) + "!" + ee.ToString());
                return;
            }

            string str_common;
            DataSet ds_ship_dist;
            DataSet ds_ship_class = new DataSet();
            try
            {
                //初始化领料类别
                if (main.dbtype == "SQL")
                {
                    str_common = "select dictionary_code,rtrim(case use_flag when '1' then ltrim(rtrim(content1)) when '2' then ltrim(rtrim(content2)) when '3' then convert(char,number1) else convert(char,number2) end) as dictionary_name from " + main.g_space + ".sys_dictionary where inv_org = '" + main.g_org + "' and ltrim(rtrim(dictionary_name))='ship_class' order by dictionary_code";
                    ds_ship_class = main.dbservice.Sql_exec_selectsql(str_common);
                }
                else
                {
                    str_common = "select dictionary_code,case use_flag when '1' then trim(content1) when '2' then trim(content2) when '3' then to_char(number1) else to_char(number2) end as dictionary_name from " + main.g_space + ".sys_dictionary where inv_org = '" + main.g_org + "' and trim(dictionary_name)='ship_class' order by dictionary_code";
                    ds_ship_class = main.dbservice.oracle_exec_selectsql(str_common);
                }

                DataRow dr = ds_ship_class.Tables[0].NewRow();
                dr["dictionary_code"] = "";
                dr["dictionary_name"] = "";
                ds_ship_class.Tables[0].Rows.Add(dr);
                cbx_standby_7.ValueMember = "dictionary_name";
                cbx_standby_7.DisplayMember = "dictionary_name";
                cbx_standby_7.DataSource = ds_ship_class.Tables[0].Copy();
                cbx_standby_7.Text = "";
                cbx_newstandby_7.ValueMember = "dictionary_name";
                cbx_newstandby_7.DisplayMember = "dictionary_name";
                cbx_newstandby_7.DataSource = ds_ship_class.Tables[0].Copy();
                //初始化领料类别
                if (main.dbtype == "SQL")
                {
                    str_common = "select distinct  rtrim(dept_class) dept_class from " + main.g_space + ".so_ld_department where inv_org='" + main.g_org + "' order by dept_class";
                    ds_ship_dist = main.dbservice.Sql_exec_selectsql(str_common);
                }
                else
                {
                    str_common = "select distinct   trim(dept_class) dept_class from " + main.g_space + ".so_ld_department where inv_org='" + main.g_org + "' order by dept_class";
                    ds_ship_dist = main.dbservice.oracle_exec_selectsql(str_common);
                }
                cbx_newstandby_8.ValueMember = "dept_class";
                cbx_newstandby_8.DisplayMember = "dept_class";
                cbx_newstandby_8.DataSource = ds_ship_dist.Tables[0].Copy();
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(ee.Message);
            }
            //自动带出审核人
            tb_maker.Text = main.g_username;

            //语言转换
            main.g_class.comm_changeControl(this, main.g_win_dataset);
        }

        private void btn_query_Click(object sender, EventArgs e)
        {
            string str_common;
            //初始化
            DataTable dt;
            dt = (DataTable)this.dg_ship_header.DataSource;
            if (dt != null)
            {
                dt.Clear();
            }

            dt = (DataTable)this.dg_ship_detail.DataSource;
            if (dt != null)
            {
                dt.Clear();
            }

            str_common = "select consignor,so_no,customer_sale_no,customer_code,customer_name,receiver,telephone,address,receive_day,so_day,case rush_flag when '0' then 'NO' else 'YES' end rush_flag,case cross_flag when '0' then 'NO' else 'YES' end cross_flag,";
            str_common = str_common + "original_order_no,so_prior,print_day,printer,confirm_day,confirmer,ship_day,shipper,";
            str_common = str_common + "wave_flag,case so_assign when '0' then 'NO' else 'YES' end so_assign,colse_day,colser,maker,made_time,memo,memo2,case so_flag when '0' then 'NORMAL' else 'CLOSE' end so_flag,so_flag so_flag2,";
            str_common = str_common + " case so_status  when '0' then '" + main.g_class.comm_getchangestring("Make", main.g_info_dataset).ToString() + "' ";
            str_common = str_common + " when '1' then '" + main.g_class.comm_getchangestring("allocation", main.g_info_dataset).ToString() + "' ";
            str_common = str_common + " when '3' then '" + main.g_class.comm_getchangestring("Part Pick", main.g_info_dataset).ToString() + "' ";
            str_common = str_common + " when '4' then '" + main.g_class.comm_getchangestring("all pick", main.g_info_dataset).ToString() + "' ";
            str_common = str_common + " when '5' then '" + main.g_class.comm_getchangestring("Shipped", main.g_info_dataset).ToString() + "' ";
            str_common = str_common + " end so_status, ";
            str_common = str_common + "case so_type when '0' then '" + main.g_class.comm_getchangestring("Outbound", main.g_info_dataset) + "' " +
                                      "when '1' then '" + main.g_class.comm_getchangestring("Return", main.g_info_dataset) + "' when '2' then '" + main.g_class.comm_getchangestring("Consignment ", main.g_info_dataset) + "' when '3' then '" +
                                      main.g_class.comm_getchangestring("Appropriation ", main.g_info_dataset) + "' when '4' then '" + main.g_class.comm_getchangestring("Sale  ", main.g_info_dataset) + "' when '5' then '" +
                                       main.g_class.comm_getchangestring("Other ", main.g_info_dataset) + "'  when '6' then '" + main.g_class.comm_getchangestring("delegate", main.g_info_dataset) + "'  when '7' then '" + main.g_class.comm_getchangestring("outsourcing", main.g_info_dataset) + "' when '8' then '" + main.g_class.comm_getchangestring("guarantees", main.g_info_dataset) + "'   else '' end as so_type ";
            str_common = str_common + " from  " + main.g_space + ".so_ship_header a where inv_org = '" + main.g_org + "' and consignor in (select consignor from " + main.g_space + ".sys_user_customer where inv_org = '" + main.g_org + "' and user_id='" + main.g_user + "')";

            if (this.cbx_customer.Text.ToString().Trim() != "")
            {
                str_common = str_common + " and consignor='" + this.cbx_customer.Text.ToString().Trim() + "'";
            }
            str_common += " and a.so_status='0' and a.standby_4=9 and a.ld_dist='1' and a.so_flag='0'";
            if (cbx_standby_7.Text.Trim() != "")
            {
                str_common += " and a.standby_7='" + cbx_standby_7.Text.Trim() + "'";
            }
            if (!string.IsNullOrEmpty(tb_maker.Text.Trim()))
            {
                str_common += " and a.auditer='" + tb_maker.Text.Trim() + "'";
            }
            if (!string.IsNullOrEmpty(tb_memo1.Text.Trim()))
            {
                str_common += " and a.memo like '%" + tb_memo1.Text.Trim() + "%'";
            }
            DataSet ds_ship_header = new DataSet();
            try
            {
                if (main.dbtype == "SQL") //sql数据库
                    ds_ship_header = main.dbservice.Sql_exec_selectsql(str_common);
                else //默认oracle数据库
                    ds_ship_header = main.dbservice.oracle_exec_selectsql(str_common);
            }
            catch (System.Exception ee)
            {
                MessageBox.Show(main.g_class.comm_getchangestring("Failed! ", main.g_info_dataset) + ee.ToString());
                return;
            }
            f_Clear();
            this.dg_ship_header.DataSource = ds_ship_header.Tables[0];
        }

        private void dg_ship_header_SelectionChanged(object sender, EventArgs e)
        {
            string str_consignor, str_so;
            if (this.dg_ship_header.CurrentRow != null)
            {
                str_consignor = this.dg_ship_header.CurrentRow.Cells[0].Value.ToString().Trim();
                str_so = this.dg_ship_header.CurrentRow.Cells[1].Value.ToString().Trim();
                f_disply_detail(str_consignor, str_so);
                f_disply(str_consignor, str_so);
                txt_back.Text = this.dg_ship_header.CurrentRow.Cells["memo2"].Value.ToString().Trim();
            }
        }

        private void btn_confirm_Click(object sender, EventArgs e)
        {
            if (this.dg_ship_header.Rows.Count <= 0) return;
            if (this.dg_ship_header.CurrentRow != null)
            {
                string str_consignor = "";
                string str_sql = "";
                string str_so_no = "";
                int i_lineno;
                str_consignor = this.dg_ship_header.CurrentRow.Cells["consignor"].Value.ToString().Trim();
                str_so_no = this.dg_ship_header.CurrentRow.Cells["so_no"].Value.ToString().Trim();
                try
                {
                    if (main.dbtype == "SQL")
                    {
                        str_sql = "update " + main.g_space + ".so_ship_header  set standby_4=1,memo=(memo+' | '+'" + main.g_user + "'+' | '+ CONVERT(varchar(100), GETDATE(), 102)) where so_no='" + str_so_no + "' and consignor='" + str_consignor + "'";
                        main.dbservice.Sql_exec_commandsql(str_sql);
                    }
                    else
                    {
                        str_sql = "update " + main.g_space + ".so_ship_header a set a.standby_4=1,a.memo=(a.memo||' | '||'" + main.g_user + "'||' | '||to_char(sysdate,'YYYY.MM.DD')) where so_no='" + str_so_no + "' and consignor='" + str_consignor + "'";
                        main.dbservice.oracle_exec_commandsql(str_sql);
                    }
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to save bill", main.g_info_dataset) + "!" + ee.ToString());
                    return;
                }

                //获得确认行的行号                
                i_lineno = dg_ship_header.CurrentRow.Index;
                btn_query_Click(sender, new EventArgs());
                //刷新后跳转到下一行 如果数据为0不操作
                if (dg_ship_header.Rows.Count > 0)
                {
                    //如果只有一行，直接显示这一行
                    if (dg_ship_header.Rows.Count == 1)
                    {
                        f_disply_detail(dg_ship_header.Rows[0].Cells["consignor"].Value.ToString().Trim(), dg_ship_header.Rows[0].Cells["so_no"].Value.ToString().Trim());
                    }
                    else //数据大于1条 
                    {
                        if (i_lineno >= dg_ship_header.Rows.Count - 1)//如果确认的行号大于等于刷新后的左边列表数量那就显示最后一条数量
                        {
                            dg_ship_header.Rows[dg_ship_header.CurrentRow.Index].Selected = false;
                            dg_ship_header.Rows[dg_ship_header.Rows.Count - 1].Selected = true;
                            f_disply_detail(dg_ship_header.Rows[dg_ship_header.Rows.Count - 1].Cells["consignor"].Value.ToString().Trim(), dg_ship_header.Rows[dg_ship_header.Rows.Count - 1].Cells["so_no"].Value.ToString().Trim());
                        }
                        else //
                        {
                            if (dg_ship_header.Rows[i_lineno].Cells["so_no"].ToString().Trim() == str_so_no.Trim())//
                            {
                                f_disply_detail(dg_ship_header.Rows[i_lineno + 1].Cells["consignor"].Value.ToString().Trim(), dg_ship_header.Rows[i_lineno + 1].Cells["so_no"].Value.ToString().Trim());
                            }
                            else
                            {

                                dg_ship_header.Rows[dg_ship_header.CurrentRow.Index].Selected = false;
                                dg_ship_header.Rows[i_lineno].Selected = true;
                                f_disply_detail(dg_ship_header.Rows[i_lineno].Cells["consignor"].Value.ToString().Trim(), dg_ship_header.Rows[i_lineno].Cells["so_no"].Value.ToString().Trim());
                            }
                        }
                    }
                }
            }
        }

        private void btn_back_Click(object sender, EventArgs e)
        {
            if (this.dg_ship_header.Rows.Count <= 0) return;
            if (this.dg_ship_header.CurrentRow != null)
            {
                string str_so_no;
                string str_consignor = "";
                string str_sql = "";
                int i_lineno;
                str_consignor = this.dg_ship_header.CurrentRow.Cells["consignor"].Value.ToString().Trim();
                str_so_no = this.dg_ship_header.CurrentRow.Cells["so_no"].Value.ToString().Trim();
                try
                {
                    if (main.dbtype == "SQL")
                    {
                        str_sql = "update " + main.g_space + ".so_ship_header  set standby_4=0,memo2='" + txt_back.Text + "',main_dist='C',updater='" + main.g_user + "',update_time=getdate() where so_no='" + str_so_no + "' and consignor='" + str_consignor + "' and inv_org='" + main.g_org + "'";
                        main.dbservice.Sql_exec_commandsql(str_sql);
                    }
                    else
                    {
                        str_sql = "update " + main.g_space + ".so_ship_header set standby_4=0,memo2='" + txt_back.Text + "',main_dist='C',updater='" + main.g_user + "',update_time=sysdate where so_no='" + str_so_no + "' and consignor='" + str_consignor + "' and inv_org='" + main.g_org + "'";
                        main.dbservice.oracle_exec_commandsql(str_sql);
                    }
                }
                catch (System.Exception ee)
                {
                    MessageBox.Show(main.g_class.comm_getchangestring("Fail to save bill", main.g_info_dataset) + "!" + ee.ToString());
                    return;
                }

                //获得确认行的行号                
                i_lineno = dg_ship_header.CurrentRow.Index;
                btn_query_Click(sender, new EventArgs());
                //刷新后跳转到下一行 如果数据为0不操作
                if (dg_ship_header.Rows.Count > 0)
                {
                    //如果只有一行，直接显示这一行
                    if (dg_ship_header.Rows.Count == 1)
                    {
                        f_disply_detail(dg_ship_header.Rows[0].Cells["consignor"].Value.ToString().Trim(), dg_ship_header.Rows[0].Cells["so_no"].Value.ToString().Trim());
                    }
                    else //数据大于1条 
                    {
                        if (i_lineno >= dg_ship_header.Rows.Count - 1)//如果确认的行号大于等于刷新后的左边列表数量那就显示最后一条数量
                        {
                            dg_ship_header.Rows[dg_ship_header.CurrentRow.Index].Selected = false;
                            dg_ship_header.Rows[dg_ship_header.Rows.Count - 1].Selected = true;
                            f_disply_detail(dg_ship_header.Rows[dg_ship_header.Rows.Count - 1].Cells["consignor"].Value.ToString().Trim(), dg_ship_header.Rows[dg_ship_header.Rows.Count - 1].Cells["so_no"].Value.ToString().Trim());
                        }
                        else //
                        {
                            if (dg_ship_header.Rows[i_lineno].Cells["so_no"].ToString().Trim() == str_so_no.Trim())//
                            {
                                f_disply_detail(dg_ship_header.Rows[i_lineno + 1].Cells["consignor"].Value.ToString().Trim(), dg_ship_header.Rows[i_lineno + 1].Cells["so_no"].Value.ToString().Trim());
                            }
                            else
                            {

                                dg_ship_header.Rows[dg_ship_header.CurrentRow.Index].Selected = false;
                                dg_ship_header.Rows[i_lineno].Selected = true;
                                f_disply_detail(dg_ship_header.Rows[i_lineno].Cells["consignor"].Value.ToString().Trim(), dg_ship_header.Rows[i_lineno].Cells["so_no"].Value.ToString().Trim());
                            }
                        }
                    }
                }
            }
        }

        private void cbx_newcustomer_TextChanged(object sender, EventArgs e)
        {
            string str_cust;
            str_cust = cbx_newcustomer.Text.Trim();
            tb_newcusname.Text = main.g_class.comm_findname(str_cust, dscustomer);
        }

        private void cbx_newcustomer_SelectedIndexChanged(object sender, EventArgs e)
        {
            string str_cust;
            str_cust = cbx_newcustomer.Text.Trim();
            tb_newcusname.Text = main.g_class.comm_findname(str_cust, dscustomer);
        }

        private void cbx_newstandby_2_SelectedIndexChanged(object sender, EventArgs e)
        {
           
        }

        private void cbx_newstandby_8_SelectedIndexChanged(object sender, EventArgs e)
        {
            cbx_newstandby_2.DataSource = null;
           
            if (cbx_newstandby_8.Text.Trim() != "")
            {
                
                string str_sql;
                #region
                ds_department = new DataSet();
                str_sql = " select dept_code,dept_name from " + main.g_space + ".so_ld_department where inv_org='" + main.g_org + "' and dept_class='" + cbx_newstandby_8.Text.Trim() + "' order by dept_code";

                try
                {
                    if (main.dbtype == "SQL")
                    {
                        ds_department = main.dbservice.Sql_exec_selectsql(str_sql);
                    }
                    else
                    {
                        ds_department = main.dbservice.oracle_exec_selectsql(str_sql);
                    }
                    if (ds_department.Tables[0].Rows.Count > 0)
                    {
                        cbx_newstandby_2.DataSource = ds_department.Tables[0];
                        cbx_newstandby_2.DisplayMember = "dept_code";
                        cbx_newstandby_2.ValueMember = "dept_code";
                    }
                }
                catch (System.Exception ee)
                {

                    MessageBox.Show(main.g_class.comm_getchangestring("初始化部门失败", main.g_info_dataset) + "!" + ee.ToString());
                }
                #endregion
             
            }
        }
    }
}
